<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目报价方案</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div id="pageInTab" class="pageInTab">
			<div tabid="tabA" title="基本信息" lselected="true">
			<div style="text-align:right">
				<span id="clxSch" class="sq-button"><a>支付表详情</a></span>
			</div>
	            <form id="formSet1">
	                <div class="fieldset1 tabel_col clearFix">
	                    <div class="fieldBox col_33">
		                    <div class="label">支付表号</div>
		                    <div class="field">
		                     <span id="paySchNo" name="paySchNo"></span>
		                   <input name="prjId" id="prjId" type="hidden" class="ui-textbox"   value="${prjId}" >
		                   <input name="prjPrdQuatId" id="prjPrdQuatId" type="hidden" class="ui-textbox"   value="${id}" >
		                    <input name="prjPrdDtlId" id="prjPrdDtlId" type="hidden" class="ui-textbox"   value="${prjPrdDtlId}" >
		            		<input name="prjPrdId" id="prjPrdId" type="hidden" class="ui-textbox"   value="${prjPrdId}" >
		            	   <input name="cstId" id="cstId" type="hidden" class="ui-textbox"  >
		            		<input name="lsPdUntCd" id="lsPdUntCd" type="hidden" class="ui-textbox"  >
		            		<input name="payWayCd" id="payWayCd" type="hidden" class="ui-textbox"  >
		            		 <input name="intRateWayCd" id="intRateWayCd" type="hidden" class="ui-textbox"  >
		            		 <input name="dpstHdlWayCd" id="dpstHdlWayCd" type="hidden" class="ui-textbox"  >
		            		 <input name="expHdlWayCd" id="expHdlWayCd" type="hidden" class="ui-textbox"  >
		            		 <input name="noPayWayCd" id="noPayWayCd" type="hidden" class="ui-textbox"  >
		            		  <input name="lsCoe" id="lsCoe" type="hidden" class="ui-textbox"  >
		            		   <input name="lsCalWayCd" id="lsCalWayCd" type="hidden" class="ui-textbox"  >
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">融资租赁合同号</div>
		                    <div class="field">
		                       <span id="lsCntNo"></span>
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">承租人</div>
		                    <div class="field">
		                        <span id="cstNm" name="cstNm"></span>
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">项目名称</div>
		                    <div class="field">
		                          <span id="prjNm" name="prjNm"></span>
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">供应商</div>
		                    <div class="field">
		                       <span id="splNm" name="splNm"></span>
		                    </div>
		                </div>
		               <div class="caption">
                                <span class="title">租赁物件清单</span>
                  	  </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">租赁物件名称</div>
		                    <div class="field">
		                    <span id="prdNm" name="prdNm"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_100">
		                    <div class="label">型号</div>
		                    <div class="field">
		                       <span id="prdMdl" name="prdMdl"></span>
								 </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">是否新车</div>
		                    <div class="field">
		                    <span id="isNewNm" name="isNewNm"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">使用期限(月)</div>
		                    <div class="field">
		                       <span id="usedPd" name="usedPd"></span>
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">单价</div>
		                    <div class="field">
		                       <span id="prdAmt" name="prdAmt"></span>
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">数量</div>
		                    <div class="field">
		                     <span id="prdQty" name="prdQty">1</span>
		                    </div>
		                </div>

		                 <div class="caption">
                                <span class="title">支付表信息</span>
                  	  </div>
		                <div class="fieldBox col_33">
		                    <div class="label">租赁物件总价值</div>
		                    <div class="field">
		                    <span id="totLsItmAmt" name="totLsItmAmt"></span>
		                    <input type="hidden" id="contAmt" name="contAmt"/>
		                    </div>
		                </div>
		                   <div class="fieldBox col_33"  id="contAmtDiv"  style="display: none">
		                    <div class="label">合同金额</div>
		                    <div class="field">
		                    <span id="prdContAmt" name="prdContAmt"></span>
		                    </div>
		                </div>

		                  <div class="fieldBox col_33">
		                    <div class="label">租赁期数</div>
		                    <div class="field">
		                    <span id="lsPd" name="lsPd"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">租赁周期</div>
		                    <div class="field">
		                     <span id="rentPeriod" name="rentPeriod"></span>
		                    </div>
		                </div>

		                   <div class="fieldBox col_33">
		                    <div class="label">租赁年利率</div>
		                    <div class="field">
		                      <span id="annIntRatePct" name="annIntRatePct"></span>
		                    </div>
		                </div>

		                   <div class="fieldBox col_33">
		                    <div class="label">实际融资租赁价值</div>
		                    <div class="field">
		                        <span id="actLsAmt" name="actLsAmt"></span>
		                    </div>
		                </div>
		               <div class="fieldBox col_33">
		                    <div class="label">租赁年利率计算方式</div>
		                    <div class="field">
		                       <span id="intRateWayCdNm" name="intRateWayCdNm"></span>
		                    </div>
		                </div>
		                <div class="fieldBox col_33">
		                    <div class="label">客户保证金处理方式</div>
		                    <div class="field">
		                      <span id="dpstHdlWayCdNm" name="dpstHdlWayCdNm"></span>
		                    </div>
		                </div>
		                <div class="fieldBox col_33">
		                    <div class="label">租赁期满处理方式</div>
		                    <div class="field">
		                        <span id="expHdlWayCdNm" name="expHdlWayCdNm"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">支付方式</div>
		                    <div class="field">
		                    	 <span id="payWayCdNm" name="payWayCdNm"></span>
		                    </div>
		                </div>

		                  <div class="fieldBox col_33">
		                    <div class="label">首付款</div>
		                    <div class="field">
		                    <span id="firstPayAmt"></span>
		                    </div>
		                </div>
		                <div class="fieldBox col_33"  id="thdPayAmtDiv"  style="display: none">
		                    <div class="label">实际应收金额</div>
		                    <div class="field">
		                    <span id="thdPayAmt"></span>
		                    </div>
		                </div>

		                   <div class="fieldBox col_33"  id="tempActLsAmtDiv"   style="display: none">
		                    <div class="label">融资租赁价值</div>
		                    <div class="field">
		                      <span id="tempActLsAmt"></span>
		                    </div>
		                </div>
		                <div class="fieldBox col_33">
		                    <div class="label">实际收益率(IRR)</div>
		                    <div class="field">
		                    <span id="irrPct"></span>
		                    </div>
		                </div>


				        <div class="fieldBox col_100">
				            <div class="sqPanel">
				                <div id="detailGrid">
				                    <div id="ligergrid_fee" class="sq-grid"></div>
				                </div>
				            </div>
				        </div>
				          <div class="fieldBox col_100">
				            <div class="sqPanel">
				                <div id="feePayGrid">
				                    <div id="ligergrid_calculate" class="sq-grid"></div>
				                </div>
				            </div>
				        </div>
				         <div class="fieldBox col_33">
		                    <div class="label">合计租金：</div>
		                    <div class="field">
		                    <span id="totalRntAmt"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">合计本金：</div>
		                    <div class="field">
		                    <span id="totalPrinAmt"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">合计利息：</div>
		                    <div class="field">
		                    <span id="totalIntAmt"></span>
		                    </div>
		                </div>
	                </div>
	            </form>
		</div>
	</div>
</div>

<script type="text/javascript">
var feeGrid;//费用明细信息
var quatId = '${quatId}';
var prjId = '${prjId}';
var calculateGrid;
var annIntRatePct = 0;
var detailFlag = '${detailFlag}';
var isClx = '${isClx}';
var sid = '${sid}';
var insCode = '${insCode}';
var isCumtomerPay = '${isCumtomerPay}';
var cumtomerPayId = '${cumtomerPayId}';
var buOrgCd = '${buOrgCd}';
var isCalFlag = '${isCalFlag}';
//费用类型
var feeTypCdListJSON = [];
<c:if test="${not empty feeTypCdListJSON}"> feeTypCdListJSON = ${feeTypCdListJSON}; </c:if>
//费用计算基数
var calBaseCdListJSON = [];
<c:if test="${not empty calBaseCdListJSON}"> calBaseCdListJSON = ${calBaseCdListJSON}; </c:if>
//费用计入方式
var cntWayCdListJSON = [];
<c:if test="${not empty cntWayCdListJSON}"> cntWayCdListJSON = ${cntWayCdListJSON}; </c:if>
//是否
var yesOrNoCdListJSON = [];
<c:if test="${not empty yesOrNoCdListJSON}"> yesOrNoCdListJSON = ${yesOrNoCdListJSON}; </c:if>
var scaleNumMap = '${scaleNumMap}';
var feeScale = 0;
var annIntScale = 0;
var floatScale = 0;
if(scaleNumMap.length>0){
	scaleNumMap = JSON.parse(scaleNumMap);
for(var key in scaleNumMap) {
	if(key==ProjectConstant.CODE_ANNINT_RATE_NUM_CD){
	annIntScale = parseInt(scaleNumMap[key]);
	}
	if(key==ProjectConstant.CODE_FLOAT_RATE_NUM_CD){
	floatScale = parseInt(scaleNumMap[key]);
	}
	if(key==ProjectConstant.CODE_FEE_DECI_NUM_CD){
	feeScale = parseInt(scaleNumMap[key]);
	}
}
} else{
	feeScale = ProjectConstant.CODE_DEF_FEE_DECI_NUM;
	annIntScale = ProjectConstant.CODE_DEF_FEE_DECI_NUM;
	floatScale = ProjectConstant.CODE_DEF_FEE_DECI_NUM;
}
$(function(){
	$('#formSet1').ligerForm({
        validate : true
	});

	var editFlag = true;
	if(detailFlag=="true"){
		editFlag = false;
		$("#calculateBtn1").hide();
		$("#saveBtn1").hide();
		$("#addBtn").hide();
		$("#delBtn").hide();
		if($("#prpsCfgNm")){
			$("#prpsCfgNm").attr("readonly","readonly");
		}
		if($("#totLsItmAmt")){
			$("#totLsItmAmt").attr("readonly","readonly");
		}
		if($("#contAmt")){
			$("#contAmt").attr("readonly","readonly");
		}
		if($("#lsPd")){
			$("#lsPd").attr("readonly","readonly");
		}
		if($("#annIntRatePct")){
			$("#annIntRatePct").attr("readonly","readonly");
		}
		if($("#actLsAmt")){
			$("#actLsAmt").attr("readonly","readonly");
		}
		if($("#eachEstRntAmt")){
			$("#eachEstRntAmt").attr("readonly","readonly");
		}
	
		if($("#lsCoe")){
			$("#lsCoe").attr("readonly","readonly");
		}
		if(liger.get("lsPdUntCd")){
			  liger.get("lsPdUntCd").setDisabled(true);
		}
		if(liger.get("payWayCd")){
			  liger.get("payWayCd").setDisabled(true);
		}
		if(liger.get("lsCalWayCd")){
			  liger.get("lsCalWayCd").setDisabled(true);
		}
		if(liger.get("intRateWayCd")){
			  liger.get("intRateWayCd").setDisabled(true);
		}
		if(liger.get("dpstHdlWayCd")){
			  liger.get("dpstHdlWayCd").setDisabled(true);
		}
		if(liger.get("expHdlWayCd")){
			  liger.get("expHdlWayCd").setDisabled(true);
		}
		if(liger.get("noPayWayCd")){
			  liger.get("noPayWayCd").setDisabled(true);
		}
	}
	$("#calculateBtn1").click(function(event) {
		initCalculateGrid();

	 });
	var id=$("#prjPrdQuatId").val();
	initPrjPrdQuatData(editFlag);
});

function prjQuatPrpsfeeGrid(data,editFlag){
	feeGrid = $("#ligergrid_fee").ligerGrid({
        data: data,
        columns: [

            {display: '费用类型', name: 'feeTypCd', minWidth: 80,
                editor: {
                    type: 'select',
                    data: feeTypCdListJSON,
                    valueField: 'code',
                    textField: 'codeNm'
                },
                valueField: 'feeTypCd',
                textField: 'feeTypCdNm',
                render: function (item) {
                    return item.feeTypCdNm;
                }
            },
            {display: '是否为固定值', name: 'isFixedAmt', minWidth: 80,
            	editor: {
                    type: 'select',
                    data: yesOrNoCdListJSON,
                    valueField: 'key',
                    textField: 'value'
                },
                valueField: 'isFixedAmt',
                textField: 'isFixedAmtNm',
                render: function (item) {
                    return item.isFixedAmtNm;
                }
            },
            {display: '计算基数', name: 'calBaseCd', minWidth: 80,
            	editor: {
                    type: 'select',
                    data: calBaseCdListJSON,
                    valueField: 'key',
                    textField: 'value'
                },
                valueField: 'calBaseCd',
                textField: 'calBaseCdNm',
                render: function (item) {
                    return item.calBaseCdNm;
                }
            },
            {display: '比例值（%）', name: 'feePct', minWidth: 80, type: 'numberbox',
              	editor: {type: 'number',
    				precision:feeScale,
    				toFix:true,
    				onToFix:function(){
    					 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多"+feeScale+"小数！"});
    				}
    		},
    	     render: function (item) {
    	     	if(item.isFixedAmt!=1){
	            	if(typeof item.feePct =='number'){
	            	var pct =  (parseFloat(item.feePct)).toFixed(2)
	                return pct;
	            	}
            	}else{
               		if(item.feeTypCd=="54" && item.feePct != null){
               			var pct =  (parseFloat(item.feePct)).toFixed(2)
       	            	return pct;
                		}else{
                			return ' ';
                		}
            	}
             }
            },
            {display: '金额', name: 'feeAmt',render:renderAmt, minWidth: 80, type: 'numberbox',
            	editor: {type: 'number'},
            },

            {display: '计入方式', name: 'cntWayCd', minWidth: 80,
            	editor: {
                    type: 'select',
                    data: cntWayCdListJSON,
                    valueField: 'key',
                    textField: 'value'
                },
                valueField: 'cntWayCd',
                textField: 'cntWayCdNm',
                render: function (item) {
                    return item.cntWayCdNm;
                }
            }

        ],
          onBeforeEdit: function(e){
           	var colNanme = e.column.columnname;
	        	if(e.record.isSysDef==1){
	        		if(colNanme!="feeAmt"){
	        		e.column.editor.readonly = true;
	        		}else{
	        			if(e.record.feeTypCd=="01"){
	        				e.column.editor.readonly = true;
	        			}else{
	        	   	        e.column.editor.readonly = false;
	        			}
	        		}
	   		 	}else{
	   		 	e.column.editor.readonly = false;
	       	 //根据行数据里的"editable"属性，指定是否可以编辑这一行数据
	            if (colNanme == "feePct" || colNanme == "calBaseCd") {
	                if (e.record.editable == 1) {
	                    e.column.editor.readonly = true;
	                }else{
	                    e.column.editor.readonly = false;
	                };
	            }
   		 	}

        },
         onAfterEdit: function (e) {
          var calBaseCd = e.record.calBaseCd;
        	if(e.column.name =="feePct"){
        		var feePct = e.value;
        		 var isFixedAmt = e.record.isFixedAmt;
        	if(typeof feePct=="number"&&isFixedAmt!="1"){
             	 var amt = getAmt(feePct,calBaseCd,isFixedAmt);
             	 feeGrid.updateCell('feePct', e.velue, e.record);
             	 feeGrid.updateCell('feeAmt', amt, e.record);
             	 }
        	}

         	if(e.column.name =="feeAmt"){
        		var feeAmt = e.value;
        		var isFixedAmt = e.record.isFixedAmt;
        		if(typeof feeAmt=="number"&&isFixedAmt!="1"){
            	 var feePct = getPct(feeAmt,calBaseCd,isFixedAmt);
             	feeGrid.updateCell('feePct', feePct, e.record);
        		}
       	}
           	if(e.column.name =="calBaseCd"){
        		 var feeTypCd = e.record.feeTypCd;
        		 var calBaseCd = e.record.calBaseCd;
        		if(feeTypCd=="01"&&calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
        			//首期款
        			top.$.ligerDialog.SQalert({SQ_type: "warning",content: "首期款的计算基数不能为融资额！"});
        		}
	       		 var feeAmt = e.record.calBaseCd;
	    		 var feePct = e.record.feePct;
	    		 var isFixedAmt = e.record.isFixedAmt;
				if(feePct){
					if(feePct>0){
						  var amt = getAmt(feePct,calBaseCd,isFixedAmt);
			             	 feeGrid.updateCell('feeAmt', amt, e.record);
					}

				}
        	}
        },
        onBeforeSubmitEdit: function (e) {//重新赋值,要不然选中后离开会把key显示在前端
            if (e.selected && e.column.columnname == "feeTypCdNm") {
                e.record.feeTypCdId = e.value;
                e.value = e.selected[e.column.editor.textField];
            }
            if (e.selected && e.column.columnname == "calBaseCdNm") {
                e.record.calBaseCdId = e.value;
                e.value = e.selected[e.column.editor.textField];
            }
            if (e.selected && e.column.columnname == "cntWayCdNm") {
                e.record.cntWayCdId = e.value;
                e.value = e.selected[e.column.editor.textField];
            }
            if (e.selected && e.column.columnname == "isFixedAmtNm") {
                e.record.isFixedAmtId = e.value;
                e.value = e.selected[e.column.editor.textField];
            }
            if(e.column.columnname == "isFixedAmt" && e.selected) e.record.editable = e.selected.key;
        },
        usePager: false,
        root: 'rows',
        record: 'total',
        hideLoadButton: true,
        width: '100%',
        height: 300,
        heightDiff: -2,
        enabledEdit: false,
        isScroll: false,
        checkbox: false,
        rownumbers: true,
        allowUnSelectRow: true,
        alternatingRow: true
    });
}

function initCalculateGrid(){
	  var form = liger.get("formSet1");
	  var data = form.getData();
	  var calculateData;
	  if(calculateGrid){
		     calculateData = calculateGrid.getData();
		 }
	    var detailListData = feeGrid.getData();
		    var id = $("#prjPrdQuatId").val();
	           data["id"]= id;
	           data["prjId"] = prjId;
	           data["cstId"]=$("#cstId").val();
	           data["paySchNo"]=$("#paySchNo").text();
	           data["totLsItmAmt"]=$("#totLsItmAmt").text();
	           data["contAmt"]=$("#contAmt").val();
	           data["lsPd"]=$("#lsPd").text();
	           data["lsPdUntCd"]=$("#lsPdUntCd").val();
	           data["annIntRatePct"]=$("#annIntRatePct").text();
	            //data["intRateRsPct"] = $("#intRateRsPct").text();
	           data["payWayCd"]=$("#payWayCd").val();
	           data["lsCalWayCd"]=$("#lsCalWayCd").val();
	           data["intRateWayCd"]=$("#intRateWayCd").val();
	           data["dpstHdlWayCd"]=$("#dpstHdlWayCd").val();
	           data["expHdlWayCd"]=$("#expHdlWayCd").val();
	           data["noPayWayCd"]=$("#noPayWayCd").val();
	           data["lsCoe"]=$("#lsCoe").val();
	           data["lsCalWayCd"]=$("#lsCalWayCd").val();
	       	 data["feeDetailList"] = JSON.stringify(detailListData);
	       	data["payList"] = JSON.stringify(calculateData);
	       	data["actLsAmt"] = $("#actLsAmt").text();
	$.ajax({
		type: 'post',
		dataType:'json',
		data:data,
		url: '<%=path%>/project/prjprdpayschm/calculate.do',
		success:function(msg){
			 if(msg.success == 1){
			var prjQuatPrps = msg.data;
				 calculateData =  msg.data.prjQuatPrpsPaySchPage;
				 $("#totalRntAmt").text(prjQuatPrps.totalRntAmt);
				 $("#totalPrinAmt").text(prjQuatPrps.totalPrinAmt);
				 $("#totalIntAmt").text(prjQuatPrps.totalIntAmt);
				 $("#firstPayAmt").text(prjQuatPrps.firstPayAmt);
				 $("#actLsAmt").val(prjQuatPrps.actLsAmt);
				 $("#eachEstRntAmt").val(prjQuatPrps.eachEstRntAmt);
				 $("#irrPct").text(null==prjQuatPrps.irrPct?"":prjQuatPrps.irrPct);
				 calculateGrid = $("#ligergrid_calculate").ligerGrid({
				    	data: $.extend(true,{},calculateData),
				        columns: [
				            { display: '应还款时间', name: 'payDt', render:renderDate, minWidth: 60 },
				            { display: '期次', name: 'payPd',minWidth: 140},
				            { display: '租金', name: 'rntAmt', minWidth: 140, render:renderAmt, type:'currency', editor: {type: 'number'},enabledSort:true},
				            { display: '本金', name: 'prinAmt', minWidth: 60, render:renderAmt,  type:'currency'},
				            { display: '利息', name: 'intAmt', minWidth: 140, render:renderAmt, type:'currency' },
				            { display: '剩余本金', name: 'remPrinAmt', render:renderAmt, minWidth: 140, type:'currency' },
				        ],
				        onBeforeEdit: function (e) {
			                e.lastValue = e.value;
			                if(!e.record.isModify){
			                	e.record.isModify= CommonConstant.C_YN_N;
			                }
			            },
				        onAfterEdit: function (e) {
				            var calBaseCd = e.record.calBaseCd;
				          	if(e.column.name =="rntAmt"){
				          		var value = e.value;
				          	var lastValue = e.lastValue;
				               	 if(value!=lastValue&&lastValue){
				               		e.record.isModify= CommonConstant.C_YN_Y;
				               	 }
				          	}

				          },
				        usePager: false,
				        pageSize:10,
				        root:'rows',
				        record:'total',
				        hideLoadButton : true,
				        width: '100%',
				        height:300,
				        heightDiff:-2,
				        //isScroll: false,
				        enabledEdit: true,
				        checkbox:false,
				        rownumbers:true
				  });
			 }
		}
	});
}

function getPct(feeAmt,calBaseCd,isFixedAmt){
	var feeFct = '';
	if(feeAmt&&isFixedAmt!="1"){
	//计算费用值
	if(calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
		//根据融资额计算
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(4);
		var totalAmt =(parseFloat($("#totLsItmAmt").text())).toFixed(4);
		  var rows = feeGrid.rows;
		var firstAmt =0;
			 for (var i = 0; i < rows.length; i++) {
			  			var feeTypCd = rows[i].feeTypCd;
				 if(feeTypCd=="01"){
					 var detailFct = parseFloat(rows[i].feePct)/100;
			  			var calCd = rows[i].calBaseCd;
			  			if(calCd==ProjectConstant.CAL_BASE_CONTRACT){
			  			firstAmt  =(detailFct*contAmt).toFixed(4);
			  			}
			  			if(calCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
			  				firstAmt  =(detailFct*totalAmt).toFixed(4);
			  			}
		  			}
			 }
			var financ = contAmt-firstAmt;
		feeFct =(parseFloat(feeAmt)/financ*100).toFixed(4);
	}

if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
		//根据合同额计算
	var contAmt = (parseFloat($("#contAmt").val())).toFixed(4);
	feeFct =(parseFloat(feeAmt)/contAmt*100).toFixed(4);
	}
	}
	return Number(feeFct);
}
function  getAmt(feePct,calBaseCd,isFixedAmt){
	 var feeAmt = '';
		 //如果存在比例值计算金额值
	if(feePct&&isFixedAmt!="1"){
		//计算费用值
		if(calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
		/* 	//根据融资额计算
			var totLsItmAmt = (parseFloat($("#totLsItmAmt").text())).toFixed(4);
			feeAmt =(parseFloat(feePct)/100*totLsItmAmt).toFixed(4); */

			//根据融资额计算
			var contAmt = (parseFloat($("#contAmt").val())).toFixed(4);
			var totalAmt =(parseFloat($("#totLsItmAmt").text())).toFixed(4);
			  var rows = feeGrid.rows;
			var firstAmt =0;
				 for (var i = 0; i < rows.length; i++) {
				  			var feeTypCd = rows[i].feeTypCd;
					 if(feeTypCd=="01"){
						 var detailFct = parseFloat(rows[i].feePct)/100;
				  			var calCd = rows[i].calBaseCd;
				  			if(calCd==ProjectConstant.CAL_BASE_CONTRACT){
				  			firstAmt  =(detailFct*contAmt).toFixed(4);
				  			}
				  			if(calCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
				  				firstAmt  =(detailFct*totalAmt).toFixed(4);
				  			}
			  			}
				 }
				var financ = contAmt-firstAmt;
			//根据设备款计算
			feeAmt =(parseFloat(feePct)/100*financ).toFixed(4);
		}

	if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			//根据合同额计算
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(4);
		feeAmt =(parseFloat(feePct)/100*contAmt).toFixed(4);
		}
	}
	return Number(feeAmt);
}

//初始化数据
function initPrjPrdQuatData(editFlag){
	var params = {};
	params.prjId=$("#prjId").val();
	params.prjPrdDtlId = $("#prjPrdDtlId").val();
	params.prjPrdId = $("#prjPrdId").val();
	params.id = $("#prjPrdQuatId").val();
	$.ajax({
		type: 'get',
		dataType:'json',
		data:params,
		url: '<%=path%>/project/prjprdpayschm/getMfrById.do',
		success:function(msg){
			 if(msg.success == 1){
				 if(msg.data){
					 setInitData(msg.data,editFlag);
				 }
			 }
		}
	});
}

	function setInitData(prjQuatPrps,editFlag){
		//汽车金融显示合同额字段
		//if(prjQuatPrps.prjBscInfo.buOrgCd==ProjectConstant.CODE_BU_ORG_CD_CAR){
			$("#contAmtDiv").show();
			//$("#prdContAmt").val(prjQuatPrps.contAmt==null?"":prjQuatPrps.contAmt);
		//}
		//初始化修改数据
	 	 var form = liger.get("formSet1");
	 	$("#totLsItmAmt").text(prjQuatPrps.totLsItmAmt==null?"":prjQuatPrps.totLsItmAmt);
	 	$("#contAmt").val(prjQuatPrps.contAmt==null?"":prjQuatPrps.contAmt);
	 	$("#prdContAmt").text(prjQuatPrps.contAmt==null?"":prjQuatPrps.contAmt);
	 	$("#lsPd").text(prjQuatPrps.lsPd==null?"":prjQuatPrps.lsPd);
	 	$("#annIntRatePct").text(prjQuatPrps.annIntRatePct==null?"":prjQuatPrps.annIntRatePct);
//	 	$("#intRateRsPct").text(prjQuatPrps.intRateRsPct==null?"":prjQuatPrps.intRateRsPct);
	    $("#actLsAmt").text(prjQuatPrps.actLsAmt==null?"":prjQuatPrps.actLsAmt);
	    $("#intRateWayCdNm").text(prjQuatPrps.intRateWayCdNm);
		$("#dpstHdlWayCdNm").text(null==prjQuatPrps.dpstHdlWayCdNm?"":prjQuatPrps.dpstHdlWayCdNm);
		$("#expHdlWayCdNm").text(null==prjQuatPrps.expHdlWayCdNm?"":prjQuatPrps.expHdlWayCdNm);
		 $("#noPayWayCdNm").text(prjQuatPrps.noPayWayCdNm);
		 $("#payWayCdNm").text(prjQuatPrps.payWayCdNm);
		 $("#cstId").val(prjQuatPrps.cstId==null?"":prjQuatPrps.cstId);
		 $("#lsPdUntCd").val(prjQuatPrps.lsPdUntCd==null?"":prjQuatPrps.lsPdUntCd);
		 $("#payWayCd").val(prjQuatPrps.payWayCd==null?"":prjQuatPrps.payWayCd);
		 $("#intRateWayCd").val(prjQuatPrps.intRateWayCd);
		 $("#dpstHdlWayCd").val(null==prjQuatPrps.dpstHdlWayCd?"":prjQuatPrps.dpstHdlWayCd);
		 $("#expHdlWayCd").val(null==prjQuatPrps.expHdlWayCd?"":prjQuatPrps.expHdlWayCd);
		 $("#noPayWayCd").val(prjQuatPrps.noPayWayCd);
		 $("#lsCalWayCd").val(prjQuatPrps.lsCalWayCd);
		 $("#initLsPc").text(prjQuatPrps.initLsPc);
		var amt =  parseFloat(prjQuatPrps.thdPayAmt/100).toFixed(2);
		 $("#thdPayAmt").text(amt);
		 $("#tempActLsAmt").text(amt);
		 $("#irrPct").text(null==prjQuatPrps.irrPct?"":prjQuatPrps.irrPct);
		 	var isSqBiz ="";
			// 浦发要求实际应收金额放在浦发支付表显示  prjQuatPrps.isSqBiz = 0  避免下面设置为1 的代码防于上方
		 	if(amt&&insCode&&insCode==ProjectConstant.PRJ_INS_CODE_PSD&& !prjQuatPrps.isSqBiz){
				$("#thdPayAmtDiv").show();
			}
			// 苏宁要求实际应收金额放在苏宁支付表显示  prjQuatPrps.isSqBiz = 0  避免下面设置为1 的代码防于上方
		 	if(amt&&insCode&&insCode==ProjectConstant.PRJ_INS_CODE_SN&& !prjQuatPrps.isSqBiz){
				$("#thdPayAmtDiv").show();
			}
			if(amt&&insCode&&insCode!=ProjectConstant.PRJ_INS_CODE_ICBC&&prjQuatPrps.isSqBiz==0){
				$("#thdPayAmtDiv").show();
			}
			if(buOrgCd==ProjectConstant.CODE_BU_ORG_CD_XNY){
				$("#tempActLsAmtDiv").show();
			}
		 $("#paySchNo").text(prjQuatPrps.paySchNo==null?"":prjQuatPrps.paySchNo);
	 		if(prjQuatPrps.prjBscInfo){
	 				$("#cstNm").text(prjQuatPrps.prjBscInfo.cstNm==null?"":prjQuatPrps.prjBscInfo.cstNm);
		 		$("#prjNm").text(prjQuatPrps.prjBscInfo.prjNm==null?"":prjQuatPrps.prjBscInfo.prjNm);
				$("#splNm").text(prjQuatPrps.prjPrdBscInfo.splNm==null?"":prjQuatPrps.prjPrdBscInfo.splNm);
				//合同号
				$("#lsCntNo").text(prjQuatPrps.prjBscInfo.lsCntNo==null?"":prjQuatPrps.prjBscInfo.lsCntNo);
	 		}
			if(prjQuatPrps.prjPrdBscInfo){
				$("#prdNm").text(prjQuatPrps.prjPrdBscInfo.prdNm==null?"":prjQuatPrps.prjPrdBscInfo.prdNm);
				if(prjQuatPrps.dtlVO){
					$("#prdMdl").text(prjQuatPrps.dtlVO.prdMdl==null?"":prjQuatPrps.dtlVO.prdMdl);
				}else{
		 		$("#prdMdl").text(prjQuatPrps.prjPrdBscInfo.prdMdl==null?"":prjQuatPrps.prjPrdBscInfo.prdMdl);
				}
				$("#isNewNm").text(prjQuatPrps.prjPrdBscInfo.isNewNm==null?"":prjQuatPrps.prjPrdBscInfo.isNewNm);
				$("#usedPd").text(prjQuatPrps.prjPrdBscInfo.usedPd==null?"":prjQuatPrps.prjPrdBscInfo.usedPd);
				$("#prdAmt").text(prjQuatPrps.prjPrdBscInfo.guidePc==null?"":prjQuatPrps.prjPrdBscInfo.guidePc);
				$("#rentPeriod").text(prjQuatPrps.lsPdUntCdNm);
		 		//$("#prdQty").text(prjQuatPrps.prjPrdBscInfo.prdQty);
			//	$("#rsrvPc").text(prjQuatPrps.prjPrdBscInfo.rsrvPc==null?"":prjQuatPrps.prjPrdBscInfo.rsrvPc);
	 		}
	 		$("#firstPayAmt").text(prjQuatPrps.firstPayAmt);
	 		$("#totalRntAmt").text(prjQuatPrps.totalRntAmt);
			$("#totalPrinAmt").text(prjQuatPrps.totalPrinAmt);
			$("#totalIntAmt").text(prjQuatPrps.totalIntAmt);
			annIntRatePct = prjQuatPrps.annIntRatePct;
	 		//setRentPeriod(prjQuatPrps.lsPd,prjQuatPrps.lsPdUntCd);
	 		initCalculatePage(prjQuatPrps.prjQuatPrpsPaySchPage,editFlag);
	 		prjQuatPrpsfeeGrid(prjQuatPrps.feeDetailListPage,editFlag);
	 		showInitLsPct();
	}

	function setRentPeriod(lsPd,lsPdUntCd){
		//根据选择的租赁单位计算租赁周期
		var rentPeriod = '';
		if(lsPd!=''){
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_MONTH){
				rentPeriod = parseFloat(lsPd)*1;
			}
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_YEAR){
				rentPeriod = parseFloat(lsPd)*12;
			}
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_DOUBLE_MONTH){
				rentPeriod = parseFloat(lsPd)*2;
			}
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_SEASON){
				rentPeriod = parseFloat(lsPd)*3;
			}
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_HALF_YEAR){
				rentPeriod = parseFloat(lsPd)*6;
			}
		}
		//设置租赁周期
		$("#rentPeriod").text(rentPeriod+"个月");
	}
	function initCalculatePage(data,editFlag){
			 var prpsId=$("#prpsId").val();
		 	calculateGrid = $("#ligergrid_calculate").ligerGrid({
			data:data,
		     columns: [
		         { display: '应还款时间', name: 'payDt', render:renderDate, minWidth: 60 },
		         { display: '期次', name: 'payPd',minWidth: 140},
		         { display: '租金', name: 'rntAmt', minWidth: 140,render:renderAmt, type:'currency',editor: {type: 'number'}, enabledSort:true},
		         { display: '本金', name: 'prinAmt', minWidth: 60, render:renderAmt, type:'currency'},
		         { display: '利息', name: 'intAmt', minWidth: 140, render:renderAmt, type:'currency' },
		         { display: '剩余本金', name: 'remPrinAmt', minWidth: 140, render:renderAmt, type:'currency' },
		     ],
		     onBeforeEdit: function (e) {
	                e.lastValue = e.value;
	                if(!e.record.isModify){
	                	e.record.isModify= CommonConstant.C_YN_N;
	                }
	            },
		        onAfterEdit: function (e) {
		            var calBaseCd = e.record.calBaseCd;
		          	if(e.column.name =="rntAmt"){
		          		var value = e.value;
		          	var lastValue = e.lastValue;
		               	 if(value!=lastValue&&lastValue){
		               		e.record.isModify= CommonConstant.C_YN_Y;
		               	 }
		          	}

		          },
		     usePager: false,
		     pageSize:10,
		     root:'rows',
		     record:'total',
		     hideLoadButton : true,
		     width: '100%',
		     height:300,
		     heightDiff:-2,
		     //isScroll: false,
		     checkbox:false,
		     enabledEdit: false,
		     rownumbers:true
		});
	}

	//格式化为人民币格式
	function renderAmt(rowdata, rowindex, value) {
		if(typeof value =='number'){
        var h="￥" + FormatMoney((parseFloat(value)).toFixed(2));
        return h;
		}
    }
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}

	function showInitLsPct(){
		var payWayCd = $("#payWayCd").val();
		if(payWayCd&&payWayCd==ProjectConstant.CODE_MULTI__STEP_INTER_ZC){
			$("#initLsPcDiv").show();
		}else{
			$("#initLsPcDiv").hide();
		}
	}
</script>



</body>
</html>
